<!--首页-->
<template>
  <div
    id="mCom"
    class="mCom"
    style="display: flex;padding: 0 5px 0 0!important"
    v-loading="showLoading"
    element-loading-text="拼命加载中..."
  >

    <div  @click="clearPop" :class=" [isCollapse?'menuOffCss':'menuOpenCss']">

      <span  :class=" [isCollapse?'closeInnerBtnBox':'openInnerBtnBox']"  @click="isCollapse = !isCollapse">
<!--        <span v-if="!isCollapse" style="font-size: 16px;color: rgba(255,255,255,0.8)">收起</span>-->
        <span class="el-icon-d-arrow-right"  v-if="isCollapse" style="display: inline-block;color: rgba(0,0,0,0.3)"></span>
        <span class="el-icon-d-arrow-left"  v-if="!isCollapse" style="display: inline-block;color: rgba(255,255,255,0.8)"></span>
      </span>

      <div v-show="!isCollapse">

        <!--      <p>我创建的目录</p>-->
        <div style="width: 160px; text-align: center;" v-if="projectList.length == 0">
          <i class="el-icon-loading"></i>
        </div>

        <div class="tree-menu" id="projctMenu" v-if="authNameStr.indexOf('我创建的任务') >= 0">
          <ul v-for="menuItem in projectList" :key="menuItem.id" style="font-family: 'Heiti SC';font-size: 14px;color: white;">

            <ProjectTree
              style="font-family: 'Heiti SC';font-size: 14px;color: white"
              @getInfoList="getInfoList"
              @getInfoListVal="getInfoListVal"
              @getClickId="getClickId"
              @refreshList="refreshList"
              :isBeAuthorList="false"
              :item="menuItem"
              :parentItem="projectList[0]"
            ></ProjectTree>

          </ul>
        </div>
        <!-- <el-tree
          :data="projectList"
          :props="defaultProps"
          @node-click="handleNodeClick"
          node-key="id"
          :default-expanded-keys="[0]"
        ></el-tree> -->

        <p style="margin-top: 26px;padding:3px 0 3px 12px;border-radius:15px;color:white;background-color: #409eff;width: 188px;font-family: 'Heiti SC';font-size: 14px" v-if="authNameStr.indexOf('我参与的任务') >= 0">我参与的</p>

        <div style="width: 160px; text-align: center" v-if="hasAuthProjectList.length == 0" v-show="authNameStr.indexOf('我参与的任务') >= 0">
          <!--        <i class="el-icon-loading"></i>-->
          <span style="display: inline-block;width: 100%;text-align: center;color:rgba(0,0,0,0.4);margin-top: 5px;">暂无数据</span>
        </div>
        <div class="tree-menu" id="projctMenuAuth" v-if="authNameStr.indexOf('我参与的任务') >= 0">
          <ul v-for="menuItem in hasAuthProjectList" :key="menuItem.id">
            <ProjectTree
              @getInfoList="getInfoList"
              @getInfoListVal="getInfoListVal"
              @getClickId="getClickId"

              :isBeAuthorList="true"
              :item="menuItem"
              :parentItem="hasAuthProjectList[0]"
            ></ProjectTree>
          </ul>
        </div>
      </div>

    </div>


    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="cancel"
    >
      <el-input v-model="addSpaceStr" placeholder="请输入文件夹名字"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </span>
    </el-dialog>

    <div style="flex: 1">
      <div class="homeMain" style="margin-top: -32px">
        <el-card id="sl" class="tBlock">
<!--          <div slot="header" class="hd clearfix">-->
<!--            <el-input-->
<!--              placeholder="输入模版名称过滤"-->
<!--              v-model="filterStr"-->
<!--              suffix-icon="el-icon-search"-->
<!--              class="search"-->
<!--              :maxlength="30"-->
<!--            >-->
<!--            </el-input>-->
<!--            <h3>-->
<!--              <a href="#"><i class="fa fa-codepen"></i>模板-->
<!--              </a>-->
<!--            </h3>-->

<!--          </div>-->
          <!-- 之前的代码 -->
          <div style="margin-bottom:20px;position: relative" v-show="authNameStr.indexOf('我创建的任务') >= 0 || authNameStr.indexOf('我参与的任务') >= 0">
            <img
              :src="require(`@/assets/img/cell-type${listType}.png`)"
              style="width:160x;height:16px;cursor: pointer;"
              @click="listType == 2 ? (listType = 2) : (listType = 2)"
            />
            <span style="display: inline-block;font-size: 16px;position: absolute;top:-1px;left:26px;">{{ NewTableData.length && NewTableData[0].isBeAuthorProject ? '我参与的' :
              (clickToolsProjectName || '我创建的') }}</span>
          </div>
<!--          <el-row :gutter="20" id="" class="pList" v-if="listType=='1'">-->
<!--            <el-col :span="4">-->
<!--              <a-->
<!--                href="javascript:void(0)"-->
<!--                @click="fastAddProject"-->
<!--                class="addProject"-->
<!--              >-->
<!--                <div class="apCom">-->
<!--                  <i class="fa fa-plus"></i><span>新建工程</span>-->
<!--                </div>-->
<!--              </a>-->
<!--            </el-col>-->
<!--            <el-col :span="4" v-for="item in templateList" :key="item.id">-->
<!--              <MainTemplateItem :item="item"></MainTemplateItem>-->
<!--            </el-col>-->
<!--          </el-row>-->
<!--          <div></div>-->
        </el-card>
        <div class="moreList"  v-if="listType=='1'">
          <a
            href="javascript:void(0)"
            @click="loadMore"
            title="更多模板"
            class="animated"
            ><i class="fa fa-angle-double-down"></i
          ></a>
        </div>
        <!-- 改成列表形式的展示 -->
        <div v-if="listType=='2'" style="position:absolute;height:100%;" :style="{width: isCollapse?'calc(100% - 35px)':'calc(100% - 205px)'}" >
          <el-table
            :data="NewTableData"
            height="calc(100vh - 100px)"
            ref="NewTableData"
            style="width: 100%;"
            :tree-props="{ children: 'project', hasChildren: 'hasChildren' }"
            row-key="id"
            :expand-row-keys="expands"
            border
            :row-style="rowStyle"
            @row-click="clickRowHandle"
          >
            <el-table-column  type="expand">
              <template slot-scope="scope">
<!--             <ComTableList :tableDataList="scope.row.dataList"></ComTableList>-->
<!--             <ComTableList :tableDataList="scope.row.documentRunInstanceList"></ComTableList>-->

                <!--运行实例列表-->
                <!--运行实例列表-->
                <!--运行实例列表-->
                <el-table
                  v-if="scope.row.documentRunInstanceList"
                  border
                  :data="scope.row.documentRunInstanceList"
                  style="width: 100%">
                  <el-table-column
                    align="center"
                    label="序号"
                    type="index"
                    width="100">
                  </el-table-column>
<!--                  <el-table-column-->
<!--                    prop="instancePath"-->
<!--                    label="实例ID"-->
<!--                    width="">-->
<!--                  </el-table-column>-->
                  <el-table-column
                    prop="instanceName"
                    label="实例名称"
                    align="center"
                    sortable
                    width="">
                  </el-table-column>
                  <el-table-column
                    prop="createTime"
                    align="center"
                    :formatter="formatDateDate_longTime"
                    show-overflow-tooltip
                    label="实例创建时间"
                    sortable
                   >
                  </el-table-column>
                  <!-- <el-table-column
                    prop="creatorName"
                    align="center"
                    label="创建人"
                    width="">
                  </el-table-column> -->
                  <!-- <el-table-column
                    prop=""
                    align="center"
                    label="状态"
                     sortable
                    width="">
                    <template slot-scope="scope">
                      运行中
                    </template>
                  </el-table-column> -->
                  <el-table-column label="操作" width="340" align="center">
                    <template slot-scope="scopeChild">
                      <el-button
                        type="text"
                        size="mini"
                        @click.stop="engineeringExampleView(scopeChild.$index, scopeChild.row,scope.row)">查看运行状态</el-button>
                      <el-button
                        type="text"
                        size="mini"
                        v-if="clickToolsProjectId!=='-99999'"
                        @click.stop="engineeringExampleDelete(scopeChild.$index, scopeChild.row,scope.row)">删除实例</el-button>
                    </template>
                  </el-table-column>

                </el-table>
                <!--运行实例列表-->
                <!--运行实例列表-->
                <!--运行实例列表-->

              </template>
            </el-table-column>


            <el-table-column prop="name" label="工具流名称" sortable align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="密级" width="120" sortable show-overflow-tooltip align="center">
              <template slot-scope="scope">
<!--                <el-tag type="success" effect="light" v-if="scope.row.project.secretLevel && scope.row.project.secretLevel.toString() === '1' ">公开</el-tag>-->
<!--                <el-tag type="warning" effect="light" v-else-if="scope.row.project.secretLevel && scope.row.project.secretLevel.toString() === '2' ">一般</el-tag>-->
<!--                <el-tag type="danger" effect="light" v-else-if="scope.row.project.secretLevel && scope.row.project.secretLevel.toString() === '3' ">重要</el-tag>-->
                <span v-if="scope.row.project.secretLevel && scope.row.project.secretLevel.toString() === '1' " style="color:green;">非密</span>
                <span v-else-if="scope.row.project.secretLevel && scope.row.project.secretLevel.toString() === '2' " style="color:orange;">秘密</span>
                <span v-else-if="scope.row.project.secretLevel && scope.row.project.secretLevel.toString() === '3' " style="color:red;">机密</span>
                <span v-else>{{scope.row.project.secretLevel}}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="createTime"
              label="创建时间"
              sortable
              :formatter="formatDateDate_longTime"
              align="center"
              show-overflow-tooltip>
            </el-table-column>
             <el-table-column prop="creatorName" v-if="isPartake" :key="Math.random()" label=" 创建人" align="center"  show-overflow-tooltip>
            </el-table-column>
             <el-table-column
              prop="project.lastOpenTime"
              :formatter="formatDateDate_longTime"
              label="最后开启时间"
              sortable
              align="center"

              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              align="center"
              v-if="!isPartake"
              :key="Math.random()"
              prop="project.description"
              label="工程描述"
              sortable
              show-overflow-tooltip>
            </el-table-column>

<!--            <el-table-column prop="project.team" label="协作团队">-->
<!--            </el-table-column>-->
            <!-- <el-table-column prop="project.userName" label="协作团队" show-overflow-tooltip>
            </el-table-column> -->


            <el-table-column v-if="!isPartake" :key="Math.random()" label="操作" width="230" align="center">
<!--              v-show="authNameStr.indexOf('我创建的任务') >= 0 || authNameStr.indexOf('我参与的任务') >= 0"-->
              <template slot-scope="scope">
                <el-button
                type="text"
                  size="mini"
                  @click.stop="projectClick(scope.$index, scope.row)">设计</el-button>
                <el-button
                type="text"
                  size="mini"
                  @click.stop="operationClick(scope.$index, scope.row)">创建运行实例</el-button>
                <!--                  @click.stop="operationClick(scope.$index, scope.row)">运行</el-button>-->
                <!-- <el-button type="text" size="mini" @click.stop="hisClick(scope.row)">历史</el-button> -->
                <el-button type="text" size="mini" @click.stop="deleteSingleData(scope.row)" style="color: red;">删除</el-button>
              </template>
            </el-table-column>

          </el-table>
        </div>
      </div>
    </div>

<el-dialog
  title="历史数据列表"
  :visible.sync="dialogVisibleHis"
  width="auto"
  :before-close="confirmHis">
   <el-scrollbar style="height:100%">
    <el-table
    height="400"
   @row-click="handleRowClick"
      :data="tableList"
      style="width: 100%">
      <el-table-column
        prop="name"
        label="工具流名称"
        width="180">
        <template slot-scope="scope">
          {{scope.row.name+'_'+scope.row.version}}
        </template>
      </el-table-column>
      <el-table-column
        prop="creatorName"
        label="创建人"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="创建时间"
         :formatter="formatDateDate_longTime"
        width="160">
      </el-table-column>
    </el-table>
   </el-scrollbar>
  <span slot="footer" class="dialog-footer">
    <!-- <el-button @click="dialogVisibleHis = false">取 消</el-button> -->
    <el-button type="primary" @click="confirmHis">确 定</el-button>
  </span>
</el-dialog>
    <ProjectContentMenu></ProjectContentMenu>
    <CopyTemplateAsProject></CopyTemplateAsProject>
    <FastCreateProjectDialog></FastCreateProjectDialog>
    <CreateProjectDialog @doingGetNewData="doingGetNewData"></CreateProjectDialog>
    <div class="domHeader">
       <el-dialog width="80%" :show-close='false' :visible.sync="dialogVisibleHisView">
      <div style="height:800px">
              <ViewTable :dataList="engineInfo"></ViewTable>
      </div>
    </el-dialog>
    </div>
   <router-view v-show="false" />
  </div>
</template>
<style scoped>
.el-card {
  border: 0;
}
/deep/.el-tree {
  background: none;
  margin-top: 20px;
}
/deep/.el-table .cell {
  line-height: 50px;
}

/deep/.el-table th.is-leaf {
  text-align: center;
}

/deep/.el-table tr {
  text-align: center;
}
/deep/ .hidden-columns .el-table__expand-column .el-icon-arrow-right {
  display: none !important;
}
/deep/ .hide-expand .el-table__expand-column .cell {
  display: none;
}
/deep/ .domHeader .el-dialog__header {
  background: none;
}

.menuOpenCss {
  width: 200px;
  opacity: 1;
  transition: all 0.2s;
  background-color: #015cac;
}

.menuOffCss {
  width: 30px !important;
  transition: all 0.2s;
  /*opacity: 0;*/
  /*opacity: 0!important;*/
  /*position: relative!important;*/
  /*background-color: red!important;*/
  /*overflow: hidden;*/
}
.openInnerBtnBox {
  width: 190px;
  height: 30px;
  text-align: right;
  line-height: 30px;
  font-size: 16px;
  cursor: pointer;
  display: inline-block;
  margin-top: 5px;
  margin-bottom: -5px;
  /*background-color: forestgreen;*/
  position: relative;
}
.closeInnerBtnBox {
  /*opacity: 1!important;*/
  width: 30px;
  height: 30px;
  line-height: 30px;
  font-size: 16px;
  cursor: pointer;
  text-align: right;
  display: inline-block;
  margin-top: 5px;
  margin-right: 10px;
  margin-bottom: -5px;
  /*background-color: forestgreen;*/
  position: relative;
}
</style>
<script>
import CreateProjectDialog from "./project/project_menu/project_tree/CreateProjectDialog.vue";
import UpdateProjectDetailDialog from "./project/project_menu/project_tree/UpdateProjectDetailDialog.vue";
import ComTableList from "./comTableList.vue";
import ViewTable from "./viewTable.vue";
import ProjectContentMenu from "./project/project_menu/project_tree/ContentMenu.vue";
import ProjectTree from "./project/project_menu/ProjectTree.vue";
import FastCreateProjectDialog from "./project/project_menu/project_tree/FastCreateProjectDialog.vue";
import CopyTemplateAsProject from "./project/project_menu/project_tree/CopyTemplateAsProject.vue";
import MainTemplateItem from "./main/MainTemplateItem.vue";
import {
  project,
  historyList,
  historyInfoList,
  runInstance,
  getHasAuthProjectList,
  createNewEngineeringExample
} from "@/api/sourceDetail";
import { DeleteSingleEngineeringExample } from "../api/sourceDetail";
import { mapGetters } from "vuex";
export default {
  name: "Main",
  data: function() {
    return {
      clickToolsProjectId: "",
      isCollapse: false,
      isPartake: undefined,
      dialogVisibleHisView: false,
      dialogVisibleHis: false,
      defaultProps: {
        children: "children",
        label: "name"
      },
      // mComStyle: {//组件绘制时动态设置容器的长宽
      //   width: "",
      //   height: ""
      // },
      listType: "2",
      fileArrList: [],
      addSpaceStr: "",
      dialogVisible: false,
      filterStr: "",
      showLoading: true,
      NewTableData: [],
      tableList: [],
      expands: [],
      tableDataList: [],
      engineInfo: {},

      hasAuthProjectList: [], //已授权工程

      clickId: null,

      isAdminAuth:
        localStorage.getItem("isAdminAuth").toString() === "1" ? true : false,
      authObj: JSON.parse(localStorage.getItem("authObj")),
      authNameStr: localStorage.getItem("authNameStr"),

      clickToolsProjectName: "" //localStorage.getItem('clickToolsProjectName'),
    };
  },
  beforeMount: function() {
    // console.log(this.authObj);
    // console.log(this.authNameStr);

    //挂载前调用
    this.$store.dispatch("checkToken");
    this.showLoading = false;
  },
  beforeUpdate() {
    this.$nextTick(() => {
      //在数据加载完，重新渲染表格
      this.$refs["NewTableData"].doLayout();
    });
  },
  created: function() {
    this.clearPop(); //清除右键菜单，如果存在
    // var w = document.documentElement.clientWidth;
    // var h = document.documentElement.clientHeight;
    // this.mComStyle.width = w - 90 + 'px';
    // this.mComStyle.height = h - 87 + 'px';
    this.$store.dispatch("getTemplateList", 0); //获取模板列表
    this.$store.dispatch("getMenuProjectList", 0); //获取工程根节点
    this.$store.dispatch("getBBSList"); //获取社区列表
    this.$store.dispatch("getDocumentsList"); //获取入门列表
    var routerPath = this.$router.currentRoute.path;
    var curMenu = this.$store.state.global.navMenu.filter(
      node => node.linkTo == routerPath
    );
    this.$store.state.global.curMenuItem = curMenu[0];
  },
  mounted() {
    console.log("%c Line:523 🍉", "color:#fca650", this.$route);
    window.addEventListener("setItem", this.updateUnreadMsgCount);

    this.getHasAuthProjectFunc(); ////获取已授权工程列表

    // console.log(this.$route.params);//isFromPageReturn
    if (
      this.$route.params &&
      this.$route.params.isFromPageReturn &&
      this.$route.params.isFromPageReturn.toString() === "true"
    ) {
      let oldClickId = localStorage.getItem("clickToolsProjectId") || "";

      if (oldClickId) {
        /////////////////////////////////////刷新table
        if (oldClickId.toString() === "-99999") {
          getHasAuthProjectList().then(res => {
            if (res.status === "SUCCESS") {
              // console.log("%c 🍐 res", "color:#ea7e5c", '已授权项目  >>>>>>>> ',JSON.parse(JSON.stringify(res)));
              res.data &&
                res.data.map(ele => {
                  ele["isBeAuthorProject"] = true;
                });
              // this.$emit("getInfoListVal", res.data);
              this.getInfoListVal(res.data, true);
            }

            setTimeout(() => {
              localStorage.removeItem("clickToolsProjectId");
            }, 100);
          });
        } else {
          project(oldClickId).then(res => {
            this.getInfoListVal(res.data, false);
            setTimeout(() => {
              localStorage.removeItem("clickToolsProjectId");
            }, 100);
          });
        }
        /////////////////////////////////////刷新table
      }
    } else {
      //////////////// 默认展示第一个目录的数据
      project(0).then(res => {
        // console.log(res);
        if (res && res.data && res.data.length) {
          // console.log(res);
          localStorage.setItem("clickToolsProjectId", res.data[0].id);
          this.resetSetItem("clickToolsProjectName", res.data[0].name);
          this.clickToolsProjectName = sessionStorage.getItem(
            "clickToolsProjectName"
          );
          project(res.data[0].id).then(val => {
            // console.log(val);
            this.getInfoListVal(val.data, false);
          });
        }
      });
      //////////////// 默认展示第一个目录的数据
    }
  },
  beforeDestroy() {
    window.removeEventListener("setItem", this.updateUnreadMsgCount);
  },
  watch: {
    "project.projectMenu": {
      handler(oldVal, newVal) {
        // this.activeIndex = this.$route.path;
        // console.log(oldVal, newVal);
        newVal &&
          newVal[0].children.map(val => {
            // console.log(val);
            if (val.hasOwnProperty("children")) {
              // val.children = []
              val.children = null;
            }
          });
      },
      deep: true
    }
    // "clickToolsProjectName":{
    //   handler(oldVal, newVal) {
    //
    //     console.log(oldVal, newVal);
    //
    //   },
    //   deep: true
    // }
  },

  computed: {
    ...mapGetters(["httpServer"]),
    project() {
      // console.log(this.$store.state.project);
      return this.$store.state.project;
    },
    projectList: function() {
      this.project.projectMenu &&
        this.project.projectMenu.map(ele => {
          ele.open = true;
        });
      this.project.projectMenu &&
        this.project.projectMenu[0].children.map(val => {
          // console.log(val);
          if (val.hasOwnProperty("children")) {
            // val.children = []
            val.children = null;
          }
        });
      // console.log(this.project.projectMenu);
      // this.project.projectMenu[0].name = "我创建的任务";
      this.project.projectMenu[0].name = "我创建的";
      //工程列表数据
      return this.project.projectMenu;
    },
    main: function() {
      return this.$store.state.main;
    },
    templateList: function() {
      //模板列表
      var list = this.main.templateList;
      var result = list.filter(
        node => node.project.name.indexOf(this.filterStr) > -1
      );
      return result;
    },
    flowData: function() {
      return this.$store.state.project.flowData;
    },
    rightContentTargetItem: function() {
      return this.flowData.rightContentTargetItem;
    }
  },
  components: {
    ViewTable,
    UpdateProjectDetailDialog,
    CreateProjectDialog,
    ProjectContentMenu,
    MainTemplateItem,
    ComTableList,
    FastCreateProjectDialog,
    CopyTemplateAsProject,
    ProjectTree
  },
  methods: {
    refreshList() {
      // console.log(111);
    },

    updateUnreadMsgCount() {
      this.clickToolsProjectName = sessionStorage.getItem(
        "clickToolsProjectName"
      );
    },

    //获取已授权工程列表
    getHasAuthProjectFunc() {
      // getHasAuthProjectList().then(res=>{
      //   // console.log(res);
      //   if(res.status === 'SUCCESS'){
      //     this.hasAuthProjectList = res.data
      //   }
      // })
      this.hasAuthProjectList = [
        {
          name: "我参与的工具流",
          // name: "我参与的",
          id: -99999,
          open: false,
          loading: false,
          createTime: "",
          creatorId: "",
          creatorName: "",
          delete: false,
          leaf: false,
          parentId: 0,
          path: "",
          sequence: "",
          children: null
        }
      ];
    },

    getInfoListVal(val, isPartake) {
      this.clickToolsProjectId = localStorage.getItem("clickToolsProjectId");
      this.isPartake = isPartake;
      this.NewTableData = val;
    },
    rowStyle(data) {
      if (data.columnIndex === 1) {
        return "cursor:pointer;";
      }
    },
    clickRowHandle(row, column, event) {
      runInstance(row.project.id).then(res => {
        this.$set(row, "dataList", res.data);
      });
      if (this.expands.includes(row.id)) {
        this.expands = this.expands.filter(val => val !== row.id);
      } else {
        this.expands.push(row.id);
      }
    },
    //历史数据工程数据
    handleRowClick(e) {
      historyInfoList(e.id, e.projectId).then(res => {
        // this.$message.success("工程获取成功");
        this.dialogVisibleHisView = true;
        this.engineInfo = res.data;
      });
    },
    confirmHis() {
      this.dialogVisibleHis = false;
    },
    hisClick(e) {
      this.dialogVisibleHis = true;
      historyList(e.project.id).then(res => {
        this.tableList = res.data;
      });
    },

    //删除单个工具流
    deleteSingleData(row) {
      if (row.creatorName === "admin" && this.isAdminAuth) {
        //都是管理员 创建的任务
      } else if (row.creatorName !== "admin" && this.isAdminAuth) {
        //不是管理员创建的、管理远登录查看的
        this.$message.info("管理员不可删除当前工具流！");
        return;
      }

      if (!this.isAdminAuth) {
        //非管理员账户
        if (this.authNameStr.indexOf("工程设计及运行") >= 0) {
          if (
            JSON.parse(localStorage.getItem("userInfo")).userName.toString() !==
            row.creatorName.toString()
          ) {
            this.$message.info("当前用户不可删除该工具流！");
            return;
          }
        } else {
          this.$message.info("当前用户不可删除该工具流！");
          return;
        }
      }
      // console.log(JSON.parse(JSON.stringify(row)));
      // console.log(JSON.parse(JSON.stringify(this.$store.state.project.flowData)));

      // this.$store.state.project.flowData.rightContentTargetItem = row
      // this.$store.state.project.flowData.currentProjectItem = row

      // if (this.flowData.isRunning) {
      //   this.$notify({
      //     title: "提示",
      //     message: "有程序正在运行，请稍后再试！",
      //     type: "warning"
      //   });
      //   return;
      // }
      this.$confirm('确认删除工具流："' + row.name + '" ？ ', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          var that = this;
          // this.$store.state.project.flowData.rightContentTargetItem = row
          this.$.ajax({
            // url: that.httpServer + "/api/project/" + that.rightContentTargetItem.project.id,
            url: that.httpServer + "/api/project/" + row.project.id,
            method: "delete",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            beforeSend: function(xhr) {
              xhr.setRequestHeader("accessToken", localStorage.accessToken);
            },
            success: function(data) {
              if (data.status == "SUCCESS") {
                that.$notify({
                  title: "提示",
                  type: "success",
                  message: "删除成功!"
                });
                // that.$store.dispatch("getMenuProjectList", 3); //更新根目录

                /////////////////////////////////////刷新table
                if (row.isBeAuthorList || row.isBeAuthorProject) {
                  //删除工具流 只有我创建的任务 会影响，  不会影响 要刷新我参与的任务的 table
                  //已参与项目（授权项目）
                  // getHasAuthProjectList().then(res => {
                  //   if (res.status === "SUCCESS") {
                  //     // console.log("%c 🍐 res", "color:#ea7e5c", '已授权项目  >>>>>>>> ',JSON.parse(JSON.stringify(res)));
                  //     res.data &&
                  //     res.data.map(ele => {
                  //       ele["isBeAuthorProject"] = true;
                  //     });
                  //     // this.$emit("getInfoListVal", res.data);
                  //     that.getInfoListVal(res.data);
                  //   }
                  // });
                } else {
                  //一般工程 项目
                  // console.log(JSON.parse(JSON.stringify(row.parentId)));
                  project(row.parentId).then(res => {
                    that.getInfoListVal(res.data);
                  });
                }
                /////////////////////////////////////刷新table

                that.$store.commit("cleanCurFlowData"); //清理当前工程的数据
              } else if (data.status == "FAIL") {
                that.$notify.error({
                  title: "提示",
                  message: "删除失败!"
                });
              }
            },
            error: function(response) {
              that.$store.commit("dealRequestError", response);
            }
          });
        })
        .catch(() => {});
    },

    getInfoList(val, isPartake) {
      console.log("%c 🎂 val", "color:#ed9ec7", val);
      // this.NewTableData = val;
    },
    clearPop: function() {
      //清理右键的弹框
      this.flowData.projectContextMenuMsg.display = "none";
      this.flowData.nodeRightContentMsg.display = "none";
      this.flowData.contextMenuMsg.display = "none";
      this.$store.state.project.modelMenu.contentMenuMessage.display = "none";
    },
    formatDate(row, column) {
      let date = new Date(row.createTime);
      let Y = date.getFullYear() + "-";
      let M = date.getMonth() + 1 + "-";
      let D = date.getDate();
      return Y + M + D;
    },
    formatDate2(row, column) {
      let date = new Date(row.project.lastOpenTime);
      let Y = date.getFullYear() + "-";
      let M = date.getMonth() + 1 + "-";
      let D = date.getDate();
      return Y + M + D;
    },
    formatDateDate_longTime(row, column) {
      const date =
          row.createTime.length === 10
            ? new Date(row.createTime * 1000)
            : new Date(row.createTime), //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        Y = date.getFullYear() + "-",
        M =
          (date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1) + "-",
        D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + "",
        h =
          (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) +
          ":",
        m =
          (date.getMinutes() < 10
            ? "0" + date.getMinutes()
            : date.getMinutes()) + ":",
        s =
          date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      // if (length === 3) {
      //   return Y + M + D;
      // } else if (length === 6) {
      return Y + M + D + " " + h + m + s;
      // }
    },
    //点击设计跳转页面
    projectClick(index, row) {
      // console.log(row);
      // return;
      // console.log(this.isAdminAuth);
      // return;
      // if(row.creatorName.indexOf('admin') >= 0 && this.isAdminAuth){ //都是管理员 创建的任务
      if (row.creatorName === "admin" && this.isAdminAuth) {
        //都是管理员 创建的任务
      } else if (row.creatorName !== "admin" && this.isAdminAuth) {
        //不是管理员创建的、管理远登录查看的
        this.$message.info("管理员不可设计当前工具流！");
        return;
      }

      if (!this.isAdminAuth) {
        //非管理员账户
        if (this.authNameStr.indexOf("工程设计及运行") >= 0) {
          if (
            JSON.parse(localStorage.getItem("userInfo")).userName.toString() !==
            row.creatorName.toString()
          ) {
            this.$message.info("当前用户不可设计该工具流！");
            return;
          }
        } else {
          this.$message.info("当前用户不可设计该工具流！");
          return;
        }
      }

      // console.log(row);
      // return
      if (row.isBeAuthorProject) {
        //TODO TODO TODO
        this.$router.push({
          path: "/home/project",
          query: { id: row.project.id, isAuth: 1, fDesign: true }
        });
      } else {
        this.$router.push({
          path: "/home/project",
          query: { id: row.project.id, fDesign: true }
        });
      }
    },

    //点击运行跳转页面
    //点击运行跳转 改为--- 》》》 新增运行实例 20230201cy
    operationClick(index, row) {
      // console.log(index, row);
      // return;
      // if(row.creatorName.indexOf('admin') >= 0 && this.isAdminAuth){ //都是管理员 创建的任务
      // }else if(row.creatorName.indexOf('admin') < 0 && this.isAdminAuth){ //不是管理员创建的、管理远登录查看的
      //   this.$message.info('管理员不可创建当前工程实例！')
      //   return
      // }
      if (row.creatorName === "admin" && this.isAdminAuth) {
        //都是管理员 创建的任务
      } else if (row.creatorName !== "admin" && this.isAdminAuth) {
        //不是管理员创建的、管理远登录查看的
        this.$message.info("管理员不可创建当前工程实例！");
        return;
      }

      if (!this.isAdminAuth) {
        //非管理员账户
        if (this.authNameStr.indexOf("工程设计及运行") >= 0) {
          if (
            JSON.parse(localStorage.getItem("userInfo")).userName.toString() !==
            row.creatorName.toString()
          ) {
            this.$message.info("当前用户不可创建该工程运行实例！");
            return;
          }
        } else {
          this.$message.info("当前用户不可创建该工程运行实例！");
          return;
        }
      }

      this.$prompt("请输入新的运行实例名称", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
        // inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
        // inputErrorMessage: '邮箱格式不正确'
      })
        .then(({ value }) => {
          if (value && value.trim() && value.trim().length >= 2) {
            createNewEngineeringExample(row.project.id, value.trim()).then(
              res => {
                // console.log(res);
                if (res.status === "SUCCESS") {
                  this.$notify.success("实例创建成功！");

                  /////////////////////////////////////刷新table
                  /////////////////////////////////////刷新table
                  if (row.isBeAuthorList || row.isBeAuthorProject) {
                    //已参与项目（授权项目）
                    getHasAuthProjectList().then(res => {
                      if (res.status === "SUCCESS") {
                        // console.log("%c 🍐 res", "color:#ea7e5c", '已授权项目  >>>>>>>> ',JSON.parse(JSON.stringify(res)));
                        res.data &&
                          res.data.map(ele => {
                            ele["isBeAuthorProject"] = true;
                          });
                        // this.$emit("getInfoListVal", res.data);
                        this.getInfoListVal(res.data);
                      }
                    });
                  } else {
                    //一般工程 项目
                    // console.log(JSON.parse(JSON.stringify(row.parentId)));
                    project(row.parentId).then(res => {
                      this.getInfoListVal(res.data);
                    });
                  }
                  /////////////////////////////////////刷新table
                  /////////////////////////////////////刷新table
                }
              }
            );
          } else {
            this.$message({
              type: "info",
              message: "实例名称太短！"
            });
            return;
          }
        })
        .catch(() => {
          // this.$message({
          //   type: 'info',
          //   message: '取消输入'
          // });
        });
    },

    getClickId(id) {
      // console.log(id);
      this.clickId = id;
    },

    // getClickName(name) {
    // console.log(name);
    // this.clickToolsProjectName = name;
    // },

    //刷新获取数据
    doingGetNewData() {
      // console.log(this.NewTableData);
      // console.log(this.clickId);
      // NewTableData.length && NewTableData[0].isBeAuthorProject ? '我参与的任务' : '我创建的任务'

      if (
        this.clickId === -99999 &&
        this.NewTableData.length &&
        this.NewTableData[0] &&
        this.NewTableData[0].isBeAuthorProject
      ) {
        //我参与的任务
        getHasAuthProjectList().then(res => {
          if (res.status === "SUCCESS") {
            res.data &&
              res.data.map(ele => {
                ele["isBeAuthorProject"] = true;
              });
            this.getInfoListVal(res.data);
          }
        });
      } else {
        //我创建的任务
        // if (!this.NewTableData[0].isBeAuthorProject) {
        //   // 选中了某个已创建的任务
        //   // console.log(this.NewTableData[0].parentId);

        //   if (
        //     this.NewTableData[0].parentId &&
        //     this.NewTableData[0].parentId != 0
        //   ) {
        project(localStorage.getItem("clickToolsProjectId")).then(res => {
          this.getInfoListVal(res.data);
        });
        //   }
        // }
      }
    },

    //工程实例查看
    engineeringExampleView(index, childRow, row) {
      localStorage.getItem("clickToolsProjectId");
      if (localStorage.getItem("clickToolsProjectId") == "-99999") {
        this.$router.push({
          path: "/home/projectTwo",
          query: {
            id: row.project.id,
            runId: childRow.id,
            pName: childRow.instanceName
          }
        });
      } else {
        if (childRow.creatorName.indexOf("admin") >= 0 && this.isAdminAuth) {
          //都是管理员 创建的任务
        } else if (
          childRow.creatorName.indexOf("admin") < 0 &&
          this.isAdminAuth
        ) {
          //不是管理员创建的、管理远登录查看的
          this.$message.info("管理员不可查看当前工程实例运行状态！");
          return;
        }

        if (childRow.creatorName === "admin" && this.isAdminAuth) {
          //都是管理员 创建的任务
        } else if (childRow.creatorName !== "admin" && this.isAdminAuth) {
          //不是管理员创建的、管理远登录查看的
          this.$message.info("管理员不可查看当前工程实例运行状态！");
          return;
        }

        if (!this.isAdminAuth) {
          //非管理员账户
          if (this.authNameStr.indexOf("工程设计及运行") >= 0) {
            if (
              JSON.parse(
                localStorage.getItem("userInfo")
              ).userName.toString() !== row.creatorName.toString()
            ) {
              this.$message.info("当前用户不可查看该实例运行状态！");
              return;
            }
          } else {
            this.$message.info("当前用户不可查看该实例运行状态！");
            return;
          }
        }

        // console.log(index, childRow,row);
        // return
        if (row.isBeAuthorProject) {
          //已参与的项目 （授权项目）
          //TODO TODO TODO
          this.$router.push({
            path: "/home/projectTwo",
            query: {
              id: row.project.id,
              runId: childRow.id,
              pName: childRow.instanceName,
              isAuth: 1
            }
          });
        } else {
          this.$router.push({
            path: "/home/projectTwo",
            query: {
              id: row.project.id,
              runId: childRow.id,
              pName: childRow.instanceName
            }
          });
        }
      }
    },

    //工程实例删除
    engineeringExampleDelete(index, childRow, row) {
      this.$confirm(
        '确认删除实例："' + childRow.instanceName + '" ？ ',
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        // console.log(index, childRow,row);
        // if(childRow.creatorName.indexOf('admin') >= 0 && this.isAdminAuth){ //都是管理员 创建的任务
        // }else if(childRow.creatorName.indexOf('admin') < 0 && this.isAdminAuth){ //不是管理员创建的、管理远登录查看的
        //   this.$message.info('管理员不可删除当前工程运行实例！')
        //   return
        // }
        if (childRow.creatorName === "admin" && this.isAdminAuth) {
          //都是管理员 创建的任务
        } else if (childRow.creatorName !== "admin" && this.isAdminAuth) {
          //不是管理员创建的、管理远登录查看的
          this.$message.info("管理员不可删除当前工程运行实例！");
          return;
        }

        if (!this.isAdminAuth) {
          //非管理员账户
          if (this.authNameStr.indexOf("工程设计及运行") >= 0) {
            if (
              JSON.parse(
                localStorage.getItem("userInfo")
              ).userName.toString() !== row.creatorName.toString()
            ) {
              this.$message.info("当前用户不可删除该实例！");
              return;
            }
          } else {
            this.$message.info("当前用户不可删除该实例！");
            return;
          }
        }

        DeleteSingleEngineeringExample(row.project.id, childRow.id).then(
          item => {
            // console.log(ele);
            if (item.status === "SUCCESS") {
              this.$notify.success("删除成功！");

              /////////////////////////////////////刷新table
              /////////////////////////////////////刷新table
              if (row.isBeAuthorList || row.isBeAuthorProject) {
                //已参与项目（授权项目）
                getHasAuthProjectList().then(res => {
                  if (res.status === "SUCCESS") {
                    // console.log("%c 🍐 res", "color:#ea7e5c", '已授权项目  >>>>>>>> ',JSON.parse(JSON.stringify(res)));
                    res.data &&
                      res.data.map(ele => {
                        ele["isBeAuthorProject"] = true;
                      });
                    // this.$emit("getInfoListVal", res.data);
                    this.getInfoListVal(res.data);
                  }
                });
              } else {
                //一般工程 项目
                // console.log(JSON.parse(JSON.stringify(row.parentId)));
                project(row.parentId).then(res => {
                  this.getInfoListVal(res.data);
                });
              }
              /////////////////////////////////////刷新table
              /////////////////////////////////////刷新table
            }
          }
        );
      });
    },

    //点击树调接口
    handleNodeClick(id) {
      project(id.id).then(res => {
        this.NewTableData = res.data;
      });
    },
    confirm() {
      this.fileArrList.push(this.addSpaceStr);
      this.$set(this.fileArrList, "");
      this.cancel();
    },
    cancel() {
      this.dialogVisible = false;
      this.addSpaceStr = "";
    },
    //新建目录
    addSpace() {
      this.dialogVisible = true;
    },
    fastAddProject() {
      //快速新建工程
      if (this.flowData.isRunning) {
        // this.$notify({
        //   type: "warning",
        //   message: "工程运行中，请稍后再试！"
        // });
        this.$message.warning("工程运行中，请稍后再试！");
        return;
      }
      //设置添加位置
      this.flowData.rightContentTargetItem = this.$store.state.project.projectMenu[0];
      //显示弹框
      this.main.showDetail.showFastCreateProjectDialog = true;
    },
    loadMore() {
      //加载更多
      this.$store.dispatch("getTemplateList", 1);
    }
  }
};
</script>
